#Simplifies the work of obs
if [[ $# == 0 ]];then
	echo "$0 PKG_NAME PKG_TAR [PKG_PATCH...] "
	exit 2
fi

src_branch='openEuler:Mainline'
my_branch='home:huanghaitao:branches:'$src_branch'/'
packages=$1
myobs_storage=/root/obs
if [ ! -d $myobs_storage ];then
	mkdir $myobs_storage
fi

branch(){
	result=`osc search $packages| grep -v home`
	if [[ ! $result =~ $src_branch ]];then
		echo "This package no exist"
		exit 1
	else
		osc branch -f $src_branch $packages $my_branch $packages
	fi
}

update(){
	pushd $myobs_storage
	rm -rf $my_branch$packages
	osc co $my_branch $packages
	pushd $my_branch$packages
	osc up -S
	if [ -d *_service:* ];then
		rename _service:tar_scm_kernel_repo: '' _service:tar_scm_kernel_repo:*
	fi
	rm -rf _service
	echo $@
	cp  -f $@ ./
	osc addremove
	osc up
	osc commit 
	popd
	popd
}

main(){
	branch $1
	update $@
}

main $@

